package com.power.leopard.remote;

import org.apache.commons.lang3.StringUtils;

import com.power.leopard.ConfigManagerLoader;
import com.power.leopard.common.util.LangUtil;
import com.power.leopard.config.ConfigManager;
import com.power.leopard.constants.Constants;

public class ServerConfig {

	private static ConfigManager configManager = ConfigManagerLoader.getConfigManager();

	public static final int DEFAULT_HTTP_PORT = 4080;
	public static final int DEFAULT_PORT = getDefaultPort();

	private String protocol = Constants.PROTOCOL_DEFAULT;

	private int port = configManager.getIntValue("pigeon.server.defaultport", DEFAULT_PORT);
	private int httpPort = configManager.getIntValue("pigeon.httpserver.defaultport", DEFAULT_HTTP_PORT);

	private int corePoolSize;
	private int maxPoolSize;
	private int workQueueSize;

	public int getCorePoolSize() {
		return corePoolSize;
	}

	public void setCorePoolSize(int corePoolSize) {
		this.corePoolSize = corePoolSize;
	}

	public int getMaxPoolSize() {
		if (maxPoolSize <= 0) {
			maxPoolSize = 5;
		}
		return maxPoolSize;
	}

	public void setMaxPoolSize(int maxPoolSize) {
		this.maxPoolSize = maxPoolSize;
	}

	public int getWorkQueueSize() {
		return workQueueSize;
	}

	public void setWorkQueueSize(int workQueueSize) {
		this.workQueueSize = workQueueSize;
	}

	public static void main(String[] args) {
		int defaultPort = getDefaultPort();
		System.out.println(defaultPort);
	}

	public static int getDefaultPort() {
		int port = 4040;
		try {
			String app = configManager.getAppName();
			if (StringUtils.isNotBlank(app)) {
				port = LangUtil.hash(app, 6000, 2000);
			}
		} catch (Throwable t) {
		}
		return port;
	}

	public String getProtocol() {
		return protocol;
	}

	public void setProtocol(String protocol) {
		this.protocol = protocol;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public int getHttpPort() {
		return httpPort;
	}

}
